package com.xuetang9.demo.ssm.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.xuetang9.demo.ssm.domain.User;
import com.xuetang9.demo.ssm.domain.dto.LoginDTO;
import com.xuetang9.demo.ssm.service.UserService;

@Controller
public class ApplicaitonController {

	// @Autowired 在IOC容器中查找是否有该类型的对象
	@Autowired
	//@Qualifier("userService")
	private UserService userService;
	
	@RequestMapping(path = "/login", method = RequestMethod.GET)
	public String login() {
		return "login";
	}
	
	@RequestMapping(path = "/login", method = RequestMethod.POST)
	public String login(LoginDTO loginDTO) {
		// 调用业务层
		User loginUser = userService.login(loginDTO);
		// 判断业务结果跳转页面
		if(loginUser == null) {
			return "login";
		}
		return "redirect:/index";
	}
	
}
